
#include "HarmonicMeanFilter.h"

void
HarmonicMeanFilter::help(std::string &buf) const
{
    buf.append(
        "谐波均值滤波器;适合处理盐粒噪声,但不适合处理胡椒噪声;\n"
        "同时也适合处理高斯噪声,以及类似噪声\n"
    );
    Filter::help(buf);
    return ;
}

double
HarmonicMeanFilter::operOnNeigh(const cv::Mat &neigh)
{
    double sum = 0;
    cv::MatConstIterator_<uchar> iter = neigh.begin<uchar>();
    cv::MatConstIterator_<uchar> const end = neigh.end<uchar>();
    for (; iter != end; ++iter) 
        sum += 1.0 / *iter;
    return (neigh.rows * neigh.cols) / sum;
}

NOISE_ALGO_REGISTER("HarmonicMeanFilter",HarmonicMeanFilter);


